package dut.ir.lxb.weibo.spider;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import dut.ir.lxb.weibo.bean.EventBean;
import dut.ir.lxb.weibo.bean.UserBean;
import dut.ir.lxb.weibo.db.EventInfoDao;
import dut.ir.lxb.weibo.db.UserInfoDao;

public class UserDownloadTestThread extends DownloadThread
{
	
	
	
	public List<EventBean> initEventList()
	{
		
		List<EventBean> eventList = new ArrayList<EventBean>();
		
		/*
		EventBean eb = new EventBean();
		eb.setUrl("http://weibo.com/p/100808ce7f80d0fec082a9db24746c8e11e64c");
		eb.setEventCode("100808ce7f80d0fec082a9db24746c8e11e64c");
		eb.setEventname("我的双11");
		eb.setHostPerson("天猫");
		eb.setType("社会");
		eb.setDescription("#我的双11#来啦！这个双11你打算怎么过？");
		eventList.add(eb);
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/1008089fc633e5562bf352698e0fdd0b582f7c?from=faxian_huati");
		eb.setEventCode("1008089fc633e5562bf352698e0fdd0b582f7c");
		eb.setEventname("双十一");
		eb.setHostPerson("天猫");
		eb.setType("社会");
		eb.setDescription("这个双十一，你打算买些什么呢？");
		eventList.add(eb);
		*/
		
		EventInfoDao eventDao = EventInfoDao.getInstance();
		EventBean eb = eventDao.getEventByName("王菲谢霆锋复合");
		eventList.add(eb);
		eb = eventDao.getEventByName("崔永元清华教授骂战");
		eventList.add(eb);
		/*
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/100808287289b8bcf029bae6c7482022c719fe?from=faxian_huati");
		eb.setEventCode("100808287289b8bcf029bae6c7482022c719fe");
		eb.setEventname("吴佩慈退出演艺圈");
		eb.setHostPerson("新浪娱乐");
		eb.setType("明星");
		eb.setDescription("13日，吴佩慈受邀出席名牌鞋款活动，产后首度公开亮相。乐于当妈的她竟然在活动上宣布：“将全面退出演艺圈！”");
		eventList.add(eb);
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/100808091a3058cd05a5d3ef88a3c95eb6508f");
		eb.setEventCode("100808091a3058cd05a5d3ef88a3c95eb6508f");
		eb.setEventname("王菲谢霆锋复合");
		eb.setHostPerson("俞健勇菲比寻常");
		eb.setType("明星");
		eb.setDescription("9月15日，有记者拍到到谢霆锋竟和王菲一起坐在车上画面，随后四天更拍摄王菲谢霆锋公寓内缠绵厮守，上演“深情之吻”。谢霆锋经纪人霍汶希在20日中午更新微博，默认复合属实，并指责狗仔偷拍行为。9月24李亚鹏发微博祝福“孩儿她娘”。");
		eventList.add(eb);
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/10080879dba347b4719fd1dc48dabf950f9414?from=faxian_huati");
		eb.setEventCode("10080879dba347b4719fd1dc48dabf950f9414");
		eb.setEventname("崔永元清华教授骂战");
		eb.setHostPerson("新浪娱乐");
		eb.setType("明星");
		eb.setDescription("近日，清华教授肖鹰批评赵本山的二人转是低俗秀，因而与崔永元在微博上掀起了一场骂战，而且至今仍在继续，骂战不断升级。");
		eventList.add(eb);
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/10080818816ab68986b500e6e667235048b803?from=faxian_huati");
		eb.setEventCode("10080818816ab68986b500e6e667235048b803");
		eb.setEventname("学生挨批泼老师热水");
		eb.setHostPerson("新京报");
		eb.setType("社会");
		eb.setDescription("华东政法大学松江校区一老师在第一节课时点名，一女生因复习考研，直到第二节课才到，老师对其进行了批评教育。课间休息时女生主动拿老师杯子去接热水，“老师还说谢谢。”不料女生端起杯子，直接泼向老师面部。据悉，该校饮水机热水常年保持98摄氏度。");
		eventList.add(eb);
		
		eb = new EventBean();
		eb.setUrl("http://weibo.com/p/100808d06a57fbb90e16fa04c3a2c0cf6515e7?from=faxian_huati");
		eb.setEventCode("100808d06a57fbb90e16fa04c3a2c0cf6515e7");
		eb.setEventname("撑同志反歧视");
		eb.setHostPerson("小雀女");
		eb.setType("社会");
		eb.setDescription("每个人都有爱的权利，爱情无关性别！！！撑同志，反歧视！");
		eventList.add(eb);
		
		eventList.addAll(eventDao.getAllEventList());
		*/
		return eventList;
	}
	
	
	
	
	@Override
	public void run()
	{
		
		WeiboDownloader wd = downloaderList.poll();
		wd.init();
		wd.setAccessDataBase(true);
		if(!wd.isLogin)
		{
			System.out.println("没有登录成功，无法进行下载");
			return;
		}
		
		while(true)
		{
			
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//List<EventBean> eventList = initEventList();
			
			UserInfoDao userDao = UserInfoDao.getInstance();
			List<UserBean> userList = userDao.getTestUserList();
			
			
			
			
			//eventList = (wd.downloadEventList(SpiderConfig.getMaxEventPageCount()));
			//eventList.addAll(initEventList());
			
			//EventInfoDao eventDao = EventInfoDao.getInstance();
			//WeiboInfoDao weiboDao = WeiboInfoDao.getInstance();
			//UserWeiboActionDao actionDao = UserWeiboActionDao.getInstance();
			
			//逐个下载事件
			for(int i = 0; i < userList.size(); i++)
			{
				//EventBean currentEvent = eventList.get(i);
				
				UserBean ub = userList.get(i);
				
				UserBean newUser;
				try {
					newUser = wd.downloadUserInfo(ub.getUid());
					userDao.insertUser(newUser);
					
					String dateValue = df.format(new Date());
					String forwardInfo = String.format("[%s] 正在下载用户 [%s]  [%s] 的个人信息", dateValue, newUser.getUid(), newUser.getNickName());
					System.out.println(forwardInfo);
					
				} catch (AccountForbiddonException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
				
				//先下载事件原始微博
				//List<WeiboBean> hotWeiboList = weiboDao.getWeiboListByEvent(currentEvent.getEventname(), false, false);
				
						
						
				
			}
		}
			
			
		
	}
	
	
}
